Package aspect.example

Source Code of aspect.example.Fighter

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package aspect.example;

import aspect.entity.Entity;
import aspect.entity.behavior.Behavior;
import aspect.physics.Motion;
import aspect.physics.RigidBody;
import static aspect.resources.Resources.*;
import aspect.util.Vector3;
import aspect.world.World;
import java.io.File;

/**
*
* @author MillerV
*/
public class Fighter extends Entity {

    private float radius = 10.0f;
   
    public float health = 100.0f;
   
    private Behavior flight;

    public Fighter(Fighter leader) {
        super(loadObjModel("fighter", new File("models/fighter.obj"), new Vector3(0.25f)));

        final Motion m = new Motion();
        m.velocity = new Vector3(0, 0, -5);
        addBehavior(m);

        if (leader == null) {
            flight = new Behavior() {
                @Override
                public void update() {
                    m.acceleration = transform.right().times(m.velocity.mag2() / radius);
                   
                    Vector3 vn = m.velocity.normalize();
                    transform.setForward(vn);
                   
                    if (m.velocity.mag() > 5) {
                        m.velocity = vn.times(5);
                    }
                }
            };
        } else {
            flight = new FollowEntity(leader);
        }
       
        addBehavior(flight);
    }

    public void die() {
        removeBehavior(flight);
       
        Motion motion = getBehavior(Motion.class);
        System.out.println(motion);
        removeBehavior(motion);
        RigidBody rigidBody = new RigidBody();
        addBehavior(rigidBody);
        rigidBody.velocity = motion.velocity;
       
        World.main.add(new Explosion(transform.position));
       
        rigidBody.impel(new Vector3(2.0f, 0, 0), new Vector3(0, 1.0f, 0));
    }
}
TOP

Related Classes of aspect.example.Fighter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.